//
//  DailyStatisticsMigration.swift
//  hello
//
//  Created by 赵康 on 2024/12/21.
//

import Fluent

extension DailyStatistics {
	struct Migration: AsyncMigration {
		var name: String { "DailyStatisticsMigration" }
		
		func prepare(on database: any Database) async throws {
			try await database.schema(DailyStatistics.schema)
				.id()
				.field(DailyStatistics.FieldKeys.date, .date, .required)
				.field(DailyStatistics.FieldKeys.totalDuration, .double, .required)
				.field(DailyStatistics.FieldKeys.user, .uuid, .required, .references(User.schema, .id))
				.field(DailyStatistics.FieldKeys.tagID, .uuid)
				.field(DailyStatistics.FieldKeys.createdAt, .datetime, .required)
				.field(DailyStatistics.FieldKeys.updatedAt, .datetime, .required)
				.create()
		}
		func revert(on database: any Database) async throws {
			try await database.schema(DailyStatistics.schema).delete()
		}
	}
}
